
import os
import time

from openlookup.client.multivalued import Proxy

URL = 'http://pdis.hiit.fi:5851/'
p = Proxy(URL)

N = 1000
key = os.urandom(10)
data = os.urandom(100)
secret = 'abracadabra'

def test_put():
    p.put(key, data, secret, ttl=60)

def test_get():
    values, cursor = p.get(key)
    assert values == [data] and not cursor

def test_rm():
    p.rm(key, data, secret, ttl=60)

def run(f, n=N):
    t0 = time.time()
    for i in range(n):
        f()
    t1 = time.time()
    return t1 - t0

print 'Put:', run(test_put)
print 'Get:', run(test_get)
print 'Rm:', run(test_rm)

print 'Put:', run(test_put)
print 'Get:', run(test_get)
print 'Rm:', run(test_rm)
